package com.lanou.musicbox.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.SeekMusic;
import com.lanou.musicbox.utils.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/10/24.
 */
public class SeekMusicAdapter extends BaseAdapter{
    private List<SeekMusic.DataEntity> data;
    private Context mContext;
    private VolleySingleton volleySingleton;

    public SeekMusicAdapter(List<SeekMusic.DataEntity> data, Context mContext) {
        this.data = data;
        this.mContext = mContext;
        volleySingleton = VolleySingleton.getVolleySingleton(mContext);
    }

    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return data != null && data.size() > 0 ? data.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.seekmusic, null);
            holder = new ViewHolder();
            holder.val = (TextView) view.findViewById(R.id.val);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        SeekMusic.DataEntity s = data.get(i);
        if (s != null) {
            holder.val.setText(s.getVal());
        }
        return view;
    }

    private class ViewHolder {
        private TextView val;
    }
}
